package com.cn.jiyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.jiyun.mapper.ScenicTicketsMapper;
import com.cn.jiyun.service.ScenicTicketsService;
import com.jiyun.entity.pojo.ScenicTickets;
import com.jiyun.result.Result;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (ScenicTickets)表服务实现类
 *
 * @author makejava
 * @since 2025-01-17 20:07:52
 */
@Service("scenicTicketsService")
public class ScenicTicketsServiceImpl extends ServiceImpl<ScenicTicketsMapper, ScenicTickets> implements ScenicTicketsService {

    @Override
    public Result<List<ScenicTickets>> findAll(String scenicName,String sort) {
        LambdaQueryWrapper<ScenicTickets> wrapper = new LambdaQueryWrapper<>();
        if (scenicName != null && !scenicName.isEmpty()) {
            wrapper.like(ScenicTickets::getScenicName, scenicName);
        }
        if (sort!= null &&!sort.isEmpty()) {
           if ("1".equals(sort)){
               wrapper.orderByAsc(ScenicTickets::getPriceStart);
           }
           if ("0".equals(sort)){
               wrapper.orderByDesc(ScenicTickets::getPriceStart);
           }
        }
        List<ScenicTickets> scenicTicketsList = baseMapper.selectList(wrapper);
        return Result.ok(scenicTicketsList);
    }
}

